//
//  YQBaseViewController.m
//  iyuanqi
//
//  Created by czl on 2017/7/27.
//  Copyright © 2017年 czl. All rights reserved.
//

#import "YQBaseViewController.h"

@interface YQBaseViewController ()

@end

@implementation YQBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)addLeftNavigationButtons:(NSArray<UIButton*>*)buttons {
    NSMutableArray* arrayButton = [NSMutableArray new];
    for (UIButton* btn in buttons) {
        [arrayButton addObject:[[UIBarButtonItem alloc] initWithCustomView:btn]];
    }
    self.navigationItem.leftBarButtonItems = arrayButton;
}

- (void)addRightNavigationButtons:(NSArray<UIButton*>*)buttons {
    NSMutableArray* arrayButton = [NSMutableArray new];
    for (UIButton* btn in buttons) {
        [arrayButton addObject:[[UIBarButtonItem alloc] initWithCustomView:btn]];
    }
    self.navigationItem.rightBarButtonItems = arrayButton;
}

- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}

//- (BOOL)hidesBottomBarWhenPushed {
//    return self.navigationController.viewControllers.count > 1;
//}

- (void)action_deliverEventsWithName:(NSString *)eventName parameter:(id)parameter {
    // 2.进阶用法：建议封装于基类VC，子类无需拦截直接实现对应即可
    SEL selector = NSSelectorFromString(eventName);
    IMP imp = [self methodForSelector:selector];
    if ([self respondsToSelector:selector]) {
        if (parameter) {
            //[self performSelector:selector withObject:userInfo];
            void (*func) (id, SEL, id) = (void *)imp;
            func(self,selector,parameter);
        } else {
            //[self performSelector:selector];
            void (*func) (id, SEL) = (void *)imp;
            func(self,selector);
        }
    } else {
        // 无法响应，继续传递
        [self.nextResponder action_deliverEventsWithName:eventName parameter:parameter];
    }
}
    
@end
